package com.simple.piger.service.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.simple.piger.constant.AjaxCode;
import com.simple.piger.dto.req.InviteCompanyEmpReqDto;
import com.simple.piger.dto.resp.company.InviteCompanyEmpRespDto;
import com.simple.piger.entity.InviteCompanyEmp;
import com.simple.piger.enums.InviteCompanyFinancingEnums;
import com.simple.piger.enums.InviteCompanyScaleEnums;
import com.simple.piger.mapper.InviteCompanyEmpMapper;
import com.simple.piger.service.ApplyUserService;
import com.simple.piger.service.CmsUserService;
import com.simple.piger.service.InviteCompanyEmpService;
import com.simple.piger.service.InviteCompanyService;
import com.simple.piger.utils.DateUtils;
import com.simple.piger.utils.PageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 公司职员 服务实现类
 * </p>
 *
 * @author baolw
 * @since 2020-02-06
 */
@Service
public class InviteCompanyEmpServiceImpl extends ServiceImpl<InviteCompanyEmpMapper, InviteCompanyEmp> implements InviteCompanyEmpService {
    @Autowired
    private ApplyUserService applyUserService;
    @Autowired
    private InviteCompanyService inviteCompanyService;
    @Autowired
    private CmsUserService cmsUserService;

    @Override
    public List<InviteCompanyEmpRespDto> list(Integer page, Integer limit, String name) {
        List<InviteCompanyEmpRespDto> list = this.baseMapper.list(PageUtil.getPageStart(page, limit), limit, name);
        return list;
    }

    @Override
    public int count(String name) {
        return this.baseMapper.count(name);
    }

    @Override
    public List<InviteCompanyEmpRespDto> platformCompanyEmpList(Integer page, Integer limit, String companyId) {
        List<InviteCompanyEmpRespDto> list = this.baseMapper.platformCompanyEmpList(PageUtil.getPageStart(page, limit), limit, companyId);
        for (InviteCompanyEmpRespDto dto : list) {
            dto.setFinancingValue(InviteCompanyFinancingEnums.transfer(dto.getFinancing()));
            dto.setScaleValue(InviteCompanyScaleEnums.transfer(dto.getScale()));
            dto.setCreateDate(DateUtils.dateFormat(dto.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
        }
        return list;
    }

    @Override
    public int platformCompanyEmpListCount(String companyId) {
        return this.baseMapper.platformCompanyEmpListCount(companyId);
    }

    @Override
    public void updateEmp(InviteCompanyEmpReqDto reqDto) {
        InviteCompanyEmp emp = this.selectById(reqDto.getId());
        emp.setUpdateTime(new Date());
        emp.setCreateTime(new Date());
        emp.setDeleteFlag("0");
        emp.setJobTitle(reqDto.getJobTitle());
        emp.setDesc(reqDto.getDesc());
        emp.setImgUrl(reqDto.getImgUrl());
        emp.updateById();
    }

    @Override
    public void saveOrUpdate(InviteCompanyEmpReqDto reqDto) {
        if (StringUtils.isNotBlank(reqDto.getId())) {
            InviteCompanyEmp emp = this.selectById(reqDto.getId());
            emp.setUpdateTime(new Date());
            emp.setCreateTime(new Date());
            emp.setDeleteFlag("0");
            emp.setJobTitle(reqDto.getJobTitle());
            emp.setDesc(reqDto.getDesc());
            emp.setImgUrl(reqDto.getImgUrl());
            emp.updateById();
        }
    }
}
